<template>
  <view class="background">
    <view class="original-balance">当前余额：{{ tradeDetailData[0].balance}}</view>
    <view class="detail">明细</view>
    <view class="scroll-container">
      <view class="detail-list" v-for="(item, index) in tradeDetailData" :key="index">
        <view>{{ item.reduceSource }}</view>
        <view>-￥{{ item.reduceAmount }}</view>
        <view>{{ item.reduceDate | formatDate}}</view>
      </view>

    </view>

    <view style="display: flex;margin-top: 60rpx;">
      <button class="button" @click="pay">前往充值</button>
    </view>
  </view>
</template>

<script>
import student from "../../api/student";

export default {
  data() {
    return {
      tradeDetailData:[{
        balance: "",
        reduceSource: "",
        reduceAmount: "",
        reduceDate: "",
        studentId: 0
      }]
    }
  },
  filters: {
    formatDate(date) {
      if (date) {
        const [datePart] = date.split(' ');
        return datePart;
      }
      return '';
    }
  },
  onLoad() {
    this.tradeDetail()

  },
  methods: {
    //校园卡交易记录
    async tradeDetail() {
      try {
         const res = await student.getTransactionRecord();
        this.tradeDetailData = res.data
      } catch (error) {
        console.error(error);
      }
    },
    //跳转充值页面
    async pay() {
      uni.navigateTo({
        url: '/pages/payment/payment', // 跳转的目标页面路径

      });
    }
  }
}
</script>

<style >
.background {
  height: 100vh; /* 使背景占满整个视口高度 */
  width: 100%;
  background: white;
  flex-direction: column; /* 使子元素垂直排列 */
  display: flex;
  align-items: center; /* 垂直居中 */

}

.original-balance {
  width: 90%;
  height: 40px;
  display: flex;
  align-items: center; /* 垂直居中 */
  justify-content: center; /* 水平居中 */
  text-align: center; /* 确保单行文本居中 */
  font-weight: bold;
  font-size: 14px;
  border-radius: 10px;
  border: 1px solid #ccc;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  margin-top: 20px;
}

.detail {
  width: 90%;
  height: 40px;
  display: flex;
  align-items: center; /* 垂直居中 */
  justify-content: center; /* 水平居中 */
  text-align: center; /* 确保单行文本居中 */
  font-weight: bold;
  font-size: 22px;
  margin-top: 10px;
}

.scroll-container {
  width: 90%;
  max-height: 300px; /* 设置最大高度，可以根据需要调整 */
  overflow-y: auto; /* 启用垂直滚动条 */
}

.detail-list {
  width: 94%;
  height: 40px;
  display: flex;
  align-items: center; /* 垂直居中 */
  justify-content: space-between; /* 水平分布 */
  font-size: 14px;
  border-radius: 10px;
  border: 1px solid #ccc;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  margin-top: 15px;
  gap: 10px; /* 设置子元素之间的间距 */
  padding: 0 10px; /* 为容器内部添加左右内边距 */
}

.button {
  border: 0;
  background-color: #bebdbd;
  color: white;
  width: 180rpx;
  font-size: 14px;
}
</style>